//
//  BAPlistData.swift
//  BadAir
//
//  Created by D on 2018/3/3.
//  Copyright © 2018年 D. All rights reserved.
//

import UIKit


class BAPlistData: NSObject {
    
    
    
    
    static let shared = BAPlistData()
    
    let path: String = NSHomeDirectory() + "/Documents/person.plist"
    
    
    
    
    func saveData(data: [String:Any]) {
        
        var plistData: NSDictionary
        
        if (FileManager.default.fileExists(atPath: path)) {
            guard let fileData = NSMutableDictionary(contentsOfFile: path) else {
                return
            }
            for (key,value) in data {
                fileData[key] = value
            }
            plistData = fileData
        }else {
            plistData = NSDictionary(dictionary: data)
        }
        
        plistData.write(toFile: path, atomically: true)
        
    }
    
    func loadData(key: String) -> Any {
        if (FileManager.default.fileExists(atPath: path)) {
            guard let fileData = NSMutableDictionary(contentsOfFile: path) else {
                return ""
            }
            return fileData[key] ?? ""
        }
        return ""
        
    }
    
}
